<?php

namespace app\admin\model;

use app\common\model\Base;

class Question extends Base {
  protected $name = 'question';

  public function initialize() {
    parent::initialize();
  }

  public function getDisableTextAttr($value, $data) {
    $status = ['启用',
               '禁用'];

    return $status[ $data['disable'] ];
  }

  /**
   * 获取指定问题的答案
   * @param mixed $ids 问题的ID ，数组或者整数
   * @param bool $field 获取的字段
   * @param null $id 指定是否以ID为数组key
   * @return array|false|\PDOStatement|string|\think\Collection
   * @throws \think\db\exception\DataNotFoundException
   * @throws \think\db\exception\ModelNotFoundException
   * @throws \think\exception\DbException
   */

  public function getQuestionAnswer($ids, $field = TRUE, $id = NULL) {
    $map = [];
    if (is_int($ids)) {
      $map['id'] = $ids;
    }else{
      $map['id'] = ['in',
                    $ids];
    }

    self::where($map)->orderRaw("find_in_set(id,'".implode(',',$ids)."')");
    if ($field === TRUE) {
      return self::field($field)->select();
    } elseif ($id === NULL) {
      return self::column($field);
    } else {
      return self::column($field, $id);
    }

  }

  public function getQuestion($ids,$field='right,type') {
    $map = [];
    if (is_int($ids)) {
      $map['id'] = $ids;
    }else{
      $map['id'] = ['in',
                    $ids];
    }


    return self::where($map)->column($field,'id');

  }


}